package com.zmzncs.shop.module.shop.service.impl;

import org.springframework.beans.BeanUtils;
import com.zmzncs.shop.module.shop.pojo.shopgoodsfile.*;
import com.zmzncs.shop.module.shop.mapper.ShopGoodsFileMapper;
import com.zmzncs.shop.module.shop.service.ShopGoodsFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 高博文
 * @since 2021-05-25
 */
@Service
public class ShopGoodsFileServiceImpl extends ServiceImpl<ShopGoodsFileMapper, ShopGoodsFile> implements ShopGoodsFileService {

    @Autowired
    private ShopGoodsFileMapper shopGoodsFileMapper;

    /**
    * 分页
    */
    @Override
    public IPage<ShopGoodsFileDTO> page(ShopGoodsFileSearchForm form){
        IPage<ShopGoodsFileDTO> iPage = shopGoodsFileMapper.list(form.getPage());

        return iPage;
    }

    /**
    * 添加
    */
    @Override
    @Transactional
    public void add(ShopGoodsFileAddForm form){
        ShopGoodsFile shopGoodsFile = new ShopGoodsFile();
        BeanUtils.copyProperties(form, shopGoodsFile);

        shopGoodsFileMapper.insert(shopGoodsFile);
    }

    /**
    * 删除
    */
    @Override
    @Transactional
    public void delete(Long id){
        ShopGoodsFile shopGoodsFile = new ShopGoodsFile();
        shopGoodsFile.setId(id);
        shopGoodsFile.setIsDeleted(1);

        shopGoodsFileMapper.updateById(shopGoodsFile);
    }

    /**
    * 修改
    */
    @Override
    @Transactional
    public void update(ShopGoodsFileUpdateForm form){
        ShopGoodsFile shopGoodsFile = new ShopGoodsFile();
        BeanUtils.copyProperties(form, shopGoodsFile);

        shopGoodsFileMapper.updateById(shopGoodsFile);
    }

    /**
    * 详情
    */
    @Override
    public ShopGoodsFileDTO getById(Long id){
        ShopGoodsFileDTO shopGoodsFileDTO = shopGoodsFileMapper.getById(id);

        return shopGoodsFileDTO;
    }

}
